home *** CD-ROM | disk | FTP | other *** search
- /*[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]*/
- /* UTEView.p */
- /* Copyright © 1986-1990 Apple Computer, Inc. All rights reserved. */
- #ifndef __TEView__
- #define __TEView__ 0
- #endif
- #if ! __TEView__
- #define __TEView__ 1
-
- /* • Auto-Include the requirements for this unit's interface. */
- #ifndef __UMacApp__
- #include "UMacApp.h"
- #endif
-
- const short kUnlimited = SHRT_MAX; /* The maximum number of characters in the
- fText of a TTEView object */
-
- const short kWithStyle = true; /* Parameters to TTEView.ITEView */
- const short kWithoutStyle = false;
- const short kSaveCurrentChars = true; /* Parameter to ITECommand */
-
- const short Chr00 ='\000'; /* Needed for ControlCharSet */
- const short Chr1F ='\037';
-
- const short kMinAhead = 96; /* Default value for fMinAhead */
-
-
- typedef unsigned long ControlCharSet;
-
- struct TEViewTemplate {
- unsigned itsStyleType : 1;
- unsigned itsAutoWrap : 1;
- unsigned itsAcceptsChanges : 1;
- unsigned itsFreesText : 1;
- unsigned filler1 : 12;
- short itsKeyCmdNumber;
- short itsMaxChars;
- Rect itsInset;
- short itsJustification;
- Style itsTextFace;
- short itsTextSize;
- RGBColor itsTextColor;
- Str255 itsFontName; /* Actually a variable length P-String */
- };
- typedef TEViewTemplate *TEViewTemplatePtr;
-
- class TTEView : public TView {
- public: /* TTEView is a view subclass representing a
- TextEdit record. TextEdit is the simple
- text-editing facility built into the
- Macintosh ROM. The purpose of a TEView is
- to make TextEdit function properly in a
- MacApp environment, for things like
- scrolling, printing, page breaks, and
- command handling */
-
- TEHandle fHTE; /* Handle to the actual TextEdit object */
-
- Handle fText; /* The text in the TEHandle */
- Handle fSavedTEHandle; /* Saved handle from TENew */
-
- Rect fInset;
- /* Amount to inset text from edges of view */
-
- CmdNumber fKeyCmdNumber; /* Will be used as the string number for
- "Undo Typing" */
-
- short fMaxChars; /* Maximum number of chars to accept into
- fText. Default is MAXINT; stuff to
- different value if you want to limit max
- chars to fewer than MAXINT */
-
- long fLastHeight; /* Last checked height of record. If the
- record is stylish, this represents the
- height in pixels. For old-style records,
-
- equals number of lines. */
-
- long fLastWidth;
- /* Last checked width of record. Not currently
- used If the TE is styled, this r
- epresents the
- width in pixels. */
-
- struct TTETypingCommand *fTypingCommand; /* The current TE Typing command relating to
- me, if any */
-
- TextStyle fTextStyle; /* Current style of text */
-
- short fJustification; /* Current justification of text record */
-
- Boolean fAcceptsChanges; /* Set to FALSE to have text which will not
- accept any change, such as text on the
- Clipboard, or perhaps received mail */
- Boolean fStyleType; /* Set to kWithStyle if record is styled */
- Boolean fAutoWrap; /* Set to FALSE for line wrapping at CR's
- only */
- Boolean fFreeText; /* Determines if fText should be freed on
- Free. */
- Boolean fSpecsChanged; /* Something recently happened which could
- effect font/style/size/color menu item
- updating. Should be reset to FALSE when
- application has taken the appropriate
- action. */
- short fLastPageBreak; /* Caches last page break computed. */
- short fLastLine;
- /* Last line of text of the last page break */
- ControlCharSet fControlChars; /* Control chars accepted in text */
- short fMinAhead;
- /* Minimum amount by which to autoscroll ahead
- when scrolling selection into vi
- ew. (When typing
- etc. */
-
- /* Initialize and Free */
-
- virtual pascal void ITEView(TDocument *itsDocument, TView *itsSuperView, VPoint *itsLocation,
- VPoint *itsSize, SizeDeterminer itsHDeterminer, SizeDeterminer itsVDeterminer, Rect *itsInset
- , TextStyle *itsTextStyle, short itsJustification, Boolean itsStyleType, Boolean itsAutoWrap);
- /* For Initialization of procedurally created TEView. */
-
- virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
- /* Initialize a TTEView via a 'view' resource. */
-
- virtual pascal void WRes(ViewRsrcHandle theResource, Ptr *itsParams);
- /* Write the object out to a view resource. */
-
- virtual pascal void WriteRes(ViewRsrcHandle theResource, Ptr *itsParams);
- /* Set up the type and signature of this object and call WRes. */
-
- virtual pascal void Free(void);
- /* Frees the TERecord and optionally fText, then frees SELF */
-
- virtual pascal void MakeTERecord(void);
- /* Called with grafport properly set, to create the actual TE Record */
-
- /* Commands and Menus */
-
- virtual pascal TCommand *DoKeyCommand(short ch, short aKeyCode, EventInfo *info);
- /* Handles keystrokes */
-
- virtual pascal struct TTECommand *DoMakeEditCommand(CmdNumber aCmdNumber);
- /* Make a command for handling edit menu stuff */
-
- virtual pascal struct TTEStyleCommand *DoMakeStyleCommand(TextStyle *aStyle, CmdNumber
- itsCmdNumber, short itsMode);
- /* Make a style change command */
-
- virtual pascal struct TTETypingCommand *DoMakeTypingCommand(short ch);
- /* Make a typing command for handling keystrokes */
-
- virtual pascal TCommand *DoMenuCommand(CmdNumber aCmdNumber);
- /* Handles menu commands */
-
- virtual pascal TCommand *DoMouseCommand(Point *theMouse, EventInfo *info, Point *hysteresis);
- /* Handles mousepresses */
-
- virtual pascal void DoneTyping(void);
- /* No further typing can occur for the current typing command */
-
- virtual pascal void DoSetupMenus(void);
- /* Sets up menus */
-
- virtual pascal void InstallSelection(Boolean wasActive, Boolean beActive);
- /* Called at activate/deactivate time to get insertion-point-blinking right (or to
- highlight the selection) */
-
- virtual pascal void ViewEnable(Boolean state, Boolean redraw);
- /* Resets the view's idle */
-
- /* Screen Display */
-
- virtual pascal Boolean DoIdle(IdlePhase phase);
- /* Blinks the insertion point */
-
- virtual pascal Boolean DoSetCursor(Point localPoint, RgnHandle cursorRgn);
- /* Sets the cursor to the I-beam */
-
- virtual pascal void Draw(Rect *area);
- /* Draw the text in a frame or on the printed page */
-
- virtual pascal void ShowReverted(void);
- /* Make sure line starts are correct before redisplay */
-
- /* Size Changes */
-
- virtual pascal void BeInPort(GrafPtr itsPort);
- /* Now that a grafport is established for the view, tells TextEdit about it */
-
- virtual pascal void BeInScroller(TScroller *itsScroller);
- /* Gives us a chance to set the scroll parameters */
-
- virtual pascal void CalcMinSize(VPoint *minSize);
- /* Compute the minimum size of the view */
-
- virtual pascal long CalcRealHeight(void);
- /* Calculate true height of record, including last character if it is a carriage
- return */
-
- virtual pascal long CalcRealWidth(void);
-
- /* Calculate true width of record. Only supported for NON-styled TE Records right now */
-
- virtual pascal void ComputeSize(VPoint *newSize);
- /* Compute the actual size of the view */
-
- virtual pascal void Resize(VCoordinate width, VCoordinate height, Boolean invalidate);
- /* Installs the new size for both the View and TextEdit */
-
- virtual pascal void SynchView(Boolean redraw);
- /* Keeps view metrics in synch after TextEdit operation. If redraw is true then
- ScrollSelectionIntoView is called to make sure the selection is visible.*/
-
- /* Clipboard */
-
-
- /* NOTE -- These methods apply only to a TEView installed as the view in the Clipboard
- */
-
- virtual pascal Boolean ContainsClipType(ResType aType);
- /* Determines whether the indicated clipboard type can be produced by the view */
-
- virtual pascal long GivePasteData(Handle aDataHandle, ResType dataType);
- /* Supplies data to be PASTED by some requesting PASTE command */
-
- virtual pascal void WriteToDeskScrap(void);
- /* Produces TEXT data for the Desk Scrap when called upon to do so */
-
- /* Miscellaneous */
-
- virtual pascal void AutoScrolling(Boolean doScrolling);
- /* Set TERecord auto scrolling to given value via TEAutoScroll */
-
- virtual pascal Boolean ClikLoop(void);
- /* Forwarded to from the global routine: ClickLoopForTTEView which was set as the
- TE's ClikLoop. Typically handles autoscrolling for the view. */
-
- virtual pascal void CalcSelLoc(Rect *selectionRect);
- /* Calculates the location of the current Selection */
-
- virtual pascal void ChangeWrap(Boolean newAutoWrap, Boolean redraw);
- /* Changes auto-wrapping behavior, redrawing if requested */
-
- virtual pascal Boolean ContinuousStyle(short firstChar, short lastChar, short *mode, TextStyle *aStyle);
- /* Returns TRUE if the style of the characters within the given range is wholly
- continuous. The style attributes to check are specified by mode, which has the same
- meaning as in the TextEdit call TESetStyle. Attributes which are continuous are
- returned in aStyle, with the appropriate bits set in mode. Font style attribute
- bits are individually checked across the selection range, and returned set to 1 if
- that attribute is continuous. */
-
- virtual pascal void ExtractStyles(TEStyleHandle *theStyles, STHandle *theElements);
- /* Extract handles to style information for a TextEdit record, presumably for the
- purpose of storing the data to disk. Note that line heights can be recalculated,
-
- and as such don't need to be stored. */
-
- virtual pascal Handle ExtractText(void);
- /* For sake of completeness. Extract handle to text, presumably for the purpose of
- storing the text externally (perhaps to disk). */
-
- virtual pascal void RecalcText(void);
- /* Tells TextEdit to recompute linestarts */
-
- virtual pascal void ScrollSelectionIntoView(void);
-
- /* Scrolls the selection into view -- called after Commands are done or undone If auto
- scrolling is on, calls TESelView to do the right thing */
-
- virtual pascal void SetJustification(short newJust, Boolean redraw);
- /* Sets the TERecord to the given justification. If redraw is true then the view is
- redrawn by calling ForceRedraw. Otherwise it is assumed the called will get the
- view redrawn. */
-
- virtual pascal void SetOneStyle(short theStart, short theEnd, short theMode, TextStyle *theStyle
- , Boolean redraw);
- /* Sets a text style continuously over a range. In unstylish TERecords, the style is
- set across the entire record. If redraw is true then the text is redrawn. */
-
- virtual pascal void SetText(StringPtr theText);
- /* Convenience routine, to save from having to create a handle just to pass to
- StuffText. Note that if fSavedTEHandle already holds a saved handle, it will be
- disposed before StuffText is called. */
-
- virtual pascal Boolean SpaceForStyles(long rangeStart, long rangeEnd);
- /* Returns TRUE if there is enough memory to hold the styles over the given range in
- the TERecord */
-
- virtual pascal void StuffStyles(TEStyleHandle theStyles, STHandle theElements);
-
- /* Installs style information, presumably fetched from disk, into the TextEdit record.
- */ /* Installs text into the TextEdit
- record.Note that this destroys any
- existing style information -- StuffStyles
- should be called if styles are to be
- attached to this text information. */
-
- virtual pascal void StuffText(Handle theText);
-
- /* Installs text into the TextEdit record. Note that this destroys any existing style
- information -- StuffStyles should be called if styles are to be attached to this
- text information */
-
- virtual pascal void StuffTERects(Rect *newTERect);
- /* installs "newTERect" as the dest & view rect of the TextEdit record */
-
- /* Printing */
-
- virtual pascal VCoordinate DoBreakFollowing(VHSelect vhs, VCoordinate prevBreak, Boolean *
- automatic);
- /* Computes the next page-break following 'prevBreak' in direction given by 'vhs' */
-
- virtual pascal void DoCalcViewPerPage(VPoint *viewPerPage);
- /* Computes how much of the view is to be allocated to each printed page */
-
- virtual pascal void DoSetPageOffset(VPoint *coord);
- /* At printing time, determine the location of the 'interior' (body)
- of the page */
-
- virtual pascal void GetPrintExtent(VRect *printExtent);
- /* Print extent is the view's extent minus the insets. */
-
- /* Debugging */
-
- virtual pascal void IdentifySoftware(void);
- /* Tells compile date of this unit */
-
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this class's
- fields. */
-
- };
-
- class TTECommand : public TCommand {
- public: /* A command that adds characters to, or
- delete characters from, a TEView */
-
- TTEView *fTEView; /* The TEView operated on */
-
- TEHandle fHTE; /* same as fTEView's fHTE; duplicated for
- code efficiency */
-
- short fOldStart;
- /* The beginning position of the selection at
- the moment just before the command was
- done. */
- short fOldEnd; /* The end position of the selection at the
- moment just before the command was done. */
- Handle fOldText; /* If fOldStart = fOldEnd, i.e., if old
- selection had been an insertion point,
-
- this will be NIL. Otherwise, provides a
- temporary home for the characters
- comprising the old selection */
- StScrpHandle fOldStyles;
-
- short fNewStart; /* The beginning location in the Text of the
- new text that is added by the command, if
- any. */
- short fNewEnd;
- /* The ending location in the Text of the new
- text that is added by the command, if any.
- */
- Handle fNewText; /* A Handle to the characters added by the
- command */
- StScrpHandle fNewStyles;
-
- Handle fPadding; /* Handle to fill size between new and old.
- This insures that we can always undo and
- redo. */
- short fTextPad;
- /* Size difference between New and Old text */
- long fStylePad;
- /* Size difference between New and Old styles
- */
-
- /* Initialize and Free */
-
- virtual pascal void ITECommand(TTEView *itsTEView, CmdNumber itsCmdNumber, Boolean itsSaveText);
- /* Initialize the command; if unsuccessful, exit is via Failure mechanism. */
-
- virtual pascal void Free(void);
-
- /* Free the text handles holding information needed for Undo/Redo, then Frees SELF */
-
- /* Command execution phase overrides */
-
- virtual pascal void DoIt(void);
- /* Focuses, then calls DoMainFunction */
-
- virtual pascal void RedoIt(void);
- /* Focuses, calls RestoreSelection to get selection right, then calls DoMainFunction
- to reinstate the changes done in DoIt which were undone by a preceding UndoIt */
-
- virtual pascal void UndoIt(void);
-
- /* Focuses, then dispatches to RemoveAdditions, ReviveDeletions, and RestoreSelection
- to accomplish the Undo */
-
-
- /* Command execution - Restoration of Selection -- called in both UNDO and REDO phases
- */
-
- virtual pascal void RestoreSelection(void);
- /* Set the Selection to be what it was just before the DO phase of the command was
- performed */
-
- /* Command execution - steps in DO and REDO phases */
-
- virtual pascal void BanishOldText(void);
- /* Remove text that was selected at the outset of the Do phase */
-
- virtual pascal void InstallNewText(void);
- /* Install the new text */
-
- virtual pascal void DoMainFunction(void);
- /* Forwards to the relevant methods for Do and Redo phases */
-
- /* Command execution - steps in UNDO phase */
-
- virtual pascal void RemoveAdditions(void);
- /* Remove any characters which were added by the DO phase of the command */
-
- virtual pascal void ReviveDeletions(void);
- /* Bring back the characters which were removed during the DO phase */
-
- /* Debugging */
-
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this class's
- fields. */
-
- };
-
- class TTECutCopyCommand : public TTECommand {
- public: /* Command for handling Cut & Copy for the
- TEView. */
- Boolean fClipCreated; /* Clipboard view created OK */
-
- /* Creation and Destruction */
-
- virtual pascal void ITECutCopyCommand(TTEView *itsTEView, CmdNumber itsCmdNumber);
- /* Initializes the command */
-
- virtual pascal void Free(void);
- /* Free the command */
-
- /* Command execution */
-
- virtual pascal void DoIt(void);
- /* Launches a TEView for installation in the Clipboard, then calls DoMainFunction */
-
- virtual pascal void ReviveDeletions(void);
- /* Bring back the characters which were removed during the DO phase; called during
- UNDO phase */
-
- /* Debugging */
-
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this class's
- fields. */
-
- };
-
- class TTEPasteCommand : public TTECommand {
- public: /* Command that handles Pasting for the
- TEView. */
-
- /* Initialization */
- virtual pascal void ITEPasteCommand(TTEView *itsTEView);
- /* Initialize the command; if unsuccessful, signalled by Failure mechanism */
-
- /* Debugging */
-
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this class's
- fields. */
-
- };
-
- class TTEStyleCommand : public TTECommand {
- public: /* Command for applying a new style to the
- TEView. */
-
- /* These two fields are only used in non-styled TextEdit records */
- short fMode; /* Mode for style change */
- TextStyle fOldTextStyle; /* The original text style */
- TextStyle fNewTextStyle; /* What we're replacing it with */
-
- /* Initialization */
-
- virtual pascal void ITEStyleCommand(TTEView *itsTEView, TextStyle *itsNewStyle, CmdNumber
- itsCmdNumber, short itsMode);
- /* Initialize the command; if unsuccessful, signalled by Failure mechanism */
-
- /* Command execution */
-
- virtual pascal void InstallOneStyle(TextStyle *newStyl);
- /* Installs one style over entire record - for use with old TextEdit */
-
- virtual pascal void InstallManyStyles(StScrpHandle newStyls);
- /* Installs styles over selection range - for use with styled TextEdit */
-
- virtual pascal void DoIt(void);
- /* Applies style to selection range */
-
- virtual pascal void UndoIt(void);
- /* Undoes the action performed by DoIt. */
-
- virtual pascal void RedoIt(void);
- /* Calls DoIt. */
-
- /* Debugging */
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this class's
- fields. */
-
- };
-
- class TTETypingCommand : public TTECommand {
- public: /* The command that handles typing in a
- TEView. */
- Boolean fCompleted; /* Indicates whether further keystrokes will
- be extensions to this command (FALSE) or
- whether the command has already been
- completed (TRUE) */
- short fFirstChar; /* First character typed */
-
- /* Creation and destruction */
-
- virtual pascal void ITETypingCommand(TTEView *itsTEView, short itsFirstChar);
- /* Initialize the command; if not successful, exit is via Failure mechanism */
-
- virtual pascal void Free(void);
- /* Deallocate the command and dependent structures */
-
- /* Command processing */
-
- virtual pascal void DoNormalChar(short aChar);
- /* Handle any typed character except a backspace */
-
- virtual pascal void BkSpcLeft(Handle theText, short curStart);
- /* Handle backspace to the left of the original selection */
-
- virtual pascal void BkSpcRight(Handle theText, short curStart);
- /* Handle backspace to the right of the original selection */
-
- virtual pascal void FwdDelete(Handle theText, short curStart, short curEnd);
- /* Handle forward delete */
-
- virtual pascal void AddCharacter(short aChar);
- /* Add another character to an already-launched TETypingCommand */
-
- virtual pascal void DoIt(void);
- /* First processing for command; adds first character */
-
- virtual pascal void RedoIt(void);
- /* Handles undoing forward backspace*/
-
- virtual pascal void UndoIt(void);
- /* Process undo typing */
-
- virtual pascal void CompleteTyping(void);
- /* Mark as no more typing allowed and fix up style scrap, if any */
-
- /* Debugging */
-
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this class's
- fields. */
-
- };
-
- /*--------------------------------------------------------------------------------------
- ------------*/
-
- extern pascal Ptr gDefClikLoopProc; /* Standard TextEdit click loop routine */
-
- /* The following are considered private, but appear in the interface in case you need to
- override a method that uses one of these. */
-
- extern pascal TTEView *pCurrTEView;
- /* For the benefit of ClikLoopForTTEView only */
- #if qDebug
- extern pascal Boolean pTEIntenseDebugging;
- #endif
-
- /*--------------------------------------------------------------------------------------
- ------------*/
-
- extern pascal void InitUTEView(void);
- /* Initialize TEView unit. */
-
- extern pascal void SetSelect(short theStart, short theEnd, TEHandle hTE);
- /* For those times when we don't want the selection range hilited when changed */
-
- extern pascal Boolean ClickLoopForTTEView(void);
- /* Called from TextEdit when the mouse is down forwards to TTEView.ClikLoop so that
- autoscrolling may be done. */
-
- extern pascal void DumpTERecord(TEHandle aTEH);
- /* writes salient information about the TERecord out to the Debug window */
-
- extern pascal void DumpTTECommand(TTECommand *theTTECommand);
- /* writes TTECommand info out to Debug window */
- #endif
-
-